package com.tamartech.greendb;

import org.apache.log4j.Logger;
import org.springframework.richclient.application.ApplicationLauncher;

public class Main
{
    private static Logger log = Logger.getLogger(Main.class);

    public static void main(String[] args)
    {
        // generate DDL (writes to console; doesn't export to db - change second SchemaExport.create param to
	// true to create the database schema, but remember that this will trash any existing schema with the 
	// same name)
	// this assumes hibernate is configured in hibernate.cfg.xml. If configuring in beans.xml, will need
	// to find another way of doing this
	// Also remember you need to create the schema using MySQL root user, and grant privileges to use bryn
	// before this will work. (Can only log into hedwig MySQL as root on hedwig)
//      org.hibernate.cfg.Configuration cfg = new AnnotationConfiguration();
//      cfg.configure();
//      new SchemaExport(cfg).create(true, false);
	
        log.info("GreenDB starting up");

        // In order to launch the platform, we have to construct an
        // application context that defines the beans (services) and
        // wiring. This is pretty much straight Spring.
        //
        // Part of this configuration will indicate the initial page to be
        // displayed.

        String rootContextDirectoryClassPath = "/com/tamartech/greendb/spring/ctx";

        // The startup context defines elements that should be available
        // quickly such as a splash screen image.

        String startupContextPath = rootContextDirectoryClassPath + "/startup-context.xml";

        String applicationContextPath = rootContextDirectoryClassPath + "/application-context.xml";

        // The ApplicationLauncher is responsible for loading the contexts,
        // presenting the splash screen, initializing the Application
        // singleton instance, creating the application window to display
        // the initial page.
        try
        {
            new ApplicationLauncher(startupContextPath, 
        	                    new String[] { applicationContextPath });
        }
        catch (RuntimeException e)
        {
            log.error("RuntimeException during startup", e);
        }
	
//	ApplicationContext context = new ClassPathXmlApplicationContext ("beans.xml");
//
//	JobDAO jobDAO = (JobDAO) context.getBean("jobDAO");
//	
//	int x = 1;
    }
}
